{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Strictly Palindromic Number"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #brainteaser #math #two-pointers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #脑筋急转弯 #数学 #双指针"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isStrictlyPalindromic"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #严格回文的数字"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>如果一个整数 <code>n</code>&nbsp;在 <code>b</code>&nbsp;进制下（<code>b</code>&nbsp;为 <code>2</code>&nbsp;到 <code>n - 2</code>&nbsp;之间的所有整数）对应的字符串&nbsp;<strong>全部</strong>&nbsp;都是 <strong>回文的</strong>&nbsp;，那么我们称这个数&nbsp;<code>n</code>&nbsp;是 <strong>严格回文</strong>&nbsp;的。</p>\n",
    "\n",
    "<p>给你一个整数&nbsp;<code>n</code>&nbsp;，如果 <code>n</code>&nbsp;是 <strong>严格回文</strong>&nbsp;的，请返回&nbsp;<code>true</code> ，否则返回<em>&nbsp;</em><code>false</code>&nbsp;。</p>\n",
    "\n",
    "<p>如果一个字符串从前往后读和从后往前读完全相同，那么这个字符串是 <strong>回文的</strong>&nbsp;。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>n = 9\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>在 2 进制下：9 = 1001 ，是回文的。\n",
    "在 3 进制下：9 = 100 ，不是回文的。\n",
    "所以，9 不是严格回文数字，我们返回 false 。\n",
    "注意在 4, 5, 6 和 7 进制下，n = 9 都不是回文的。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><b>输入：</b>n = 4\n",
    "<b>输出：</b>false\n",
    "<b>解释：</b>我们只考虑 2 进制：4 = 100 ，不是回文的。\n",
    "所以我们返回 false 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>4 &lt;= n &lt;= 10<sup>5</sup></code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [strictly-palindromic-number](https://leetcode.cn/problems/strictly-palindromic-number/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [strictly-palindromic-number](https://leetcode.cn/problems/strictly-palindromic-number/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['9', '4']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def fun(n: int, b: int) -> List[int]:\n",
    "            res = []\n",
    "            while n:\n",
    "                res.append(n % b)\n",
    "                n  //= b\n",
    "            return res\n",
    "        for b in range(2, n-1):\n",
    "            num = fun(n, b)\n",
    "            if num != num[::-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        b = 2\n",
    "        list = []\n",
    "        for i in range(2,n-1):\n",
    "            flag = n\n",
    "\n",
    "            lst = []\n",
    "\n",
    "            while flag != 0:\n",
    "                lst.insert(0, flag % b)\n",
    "                flag = flag // b\n",
    "\n",
    "            lst1 = lst[::-1]\n",
    "\n",
    "            if(lst == lst1):\n",
    "                list.append('1')\n",
    "            else:\n",
    "                list.append('0')\n",
    "\n",
    "            b+=1\n",
    "        if '0' in list:\n",
    "            return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        if n==3:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "     def helper(num,b):\n",
    "      d=b\n",
    "      res=[]\n",
    "      while num>d:\n",
    "       d*=b\n",
    "      d/=b\n",
    "      while num:\n",
    "       n,num=divmod(num,d)\n",
    "       d/=b\n",
    "       res.append(n)\n",
    "      if res[-1]==res:\n",
    "       return 0\n",
    "      else:\n",
    "       return 1\n",
    "     l=[]\n",
    "     for b in range(2,n-1):\n",
    "      l.append(helper(n,b))\n",
    "     return sum(l)==0\n",
    "      \n",
    "      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return 1==2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        num = n\n",
    "        for i in range(2, n-1):\n",
    "            s = ''\n",
    "            n = num\n",
    "            while n > 0:\n",
    "                s = str(n % i) + s\n",
    "                n = n // i\n",
    "            if s != s[::-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def zhuanhuan(base, num):\n",
    "            result = \"\"\n",
    "            remainder = num\n",
    "            while remainder > 0:\n",
    "                remainder, digit = divmod(remainder, base)\n",
    "                result = str(digit) + result\n",
    "            return result == result[::-1]\n",
    "        for i in range(2, n-1):\n",
    "            if zhuanhuan(i, n) == False:\n",
    "                return False\n",
    "        return True\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for b in range(n-1, 1, -1):\n",
    "            m = int(log(n, b))\n",
    "            divider = b**m\n",
    "            rr = ln = n\n",
    "            for _ in range((m+1)>>1):\n",
    "                rn, rr = divmod(rr, b)\n",
    "                ln, lr = divmod(ln, divider)\n",
    "                if lr != rn: return False\n",
    "                divider //= b\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return not True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for i in range(2,n-1):\n",
    "            m=format(str(n),str(i))\n",
    "            if str(m)!=str(m[::-1]):\n",
    "                return False\n",
    "                break\n",
    "        return True "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        base = 2\n",
    "        while base <= n-2:\n",
    "            nbase = self.convertToNBase(n, base)\n",
    "            if not self.isPalimdromic(nbase):\n",
    "                return False\n",
    "            base += 1\n",
    "        return True\n",
    "        # assert self.isPalimdromic('1001')\n",
    "\n",
    "    def isPalimdromic(self, s: str) -> bool:\n",
    "        chars = list(s)\n",
    "        while len(chars)>1:\n",
    "            s = chars.pop(0)\n",
    "            e = chars.pop()\n",
    "            if s != e:\n",
    "                return False\n",
    "        return True\n",
    "    \n",
    "    def convertToNBase(self, number: int, base: int) -> str:\n",
    "        result = ''\n",
    "        n = 0\n",
    "        while number > 0:\n",
    "            r = number % base\n",
    "            result = str(r) + result\n",
    "            number = number // base\n",
    "        print(result)\n",
    "        return result\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return n==3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def trans(x: int, n: int) -> bool:\n",
    "            ans = []\n",
    "            while n/x > 0:\n",
    "                ans.append(n % x)\n",
    "                n //= x\n",
    "            return ans == ans[::-1]\n",
    "        for i in range(2, n - 1):\n",
    "            if not trans(i, n):\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def conv(n, b):\n",
    "            ans = []\n",
    "            while n>0:\n",
    "                ans.append(str(n%b))\n",
    "                n = n//b\n",
    "            ans = ans[::-1]\n",
    "            return \"\".join(ans)\n",
    "\n",
    "        def isPrime(s):\n",
    "            return s == s[::-1]\n",
    "\n",
    "        for b in range(2, n-1):\n",
    "            if not isPrime(conv(n, b)):\n",
    "                return False\n",
    "        return True            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        b = bin(n)\n",
    "        print(b)\n",
    "        if b == b[::-1]:\n",
    "            return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "         return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for b in range(2, n - 1):\n",
    "            num = n\n",
    "            w = ''\n",
    "            while num > 0:\n",
    "                w += str(num % b)\n",
    "                num /= b \n",
    "            if w != w[::-1]:\n",
    "                return False \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def f(n,b):\n",
    "            a=[]\n",
    "            while n!=0:\n",
    "                a.append(n%b)\n",
    "                n//=b\n",
    "            if a==a[::-1]:\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        \n",
    "        for i in range(2,n-1,1):\n",
    "            if f(n,i)==False:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for i in range(2,n-1):\n",
    "            tmp = n\n",
    "            nBaseI = []\n",
    "            while tmp!=0:\n",
    "                nBaseI.append(tmp%i)\n",
    "                tmp = tmp//i\n",
    "            if nBaseI!=nBaseI[::-1]:\n",
    "                return False\n",
    "        return True\n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def ok(n, b):\n",
    "            res = []\n",
    "            while n:\n",
    "                res.append(n%b)\n",
    "                n//=b\n",
    "            return res\n",
    "        for i in range(2,n-1):\n",
    "            num = ok(n,i)\n",
    "            if num != num[::-1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for i in range(2, n - 1):\n",
    "            jinzhi = []\n",
    "            m = n\n",
    "            while n:\n",
    "                jinzhi.append(n % i)\n",
    "                n = n // i\n",
    "            # print(jinzhi)\n",
    "            if jinzhi != jinzhi[::-1]:\n",
    "                return False               \n",
    "            n = m\n",
    "        return True\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        num=n\n",
    "        for j in range(2,num-2+1):\n",
    "            a=[]\n",
    "            c=[]\n",
    "            n=num           \n",
    "            while n>0:            \n",
    "               b=n%j\n",
    "               n=n//j\n",
    "               a.append(b)\n",
    "            for i in range(len(a)):\n",
    "                if a[i]!=a[-i-1]:\n",
    "                    return False              \n",
    "        return True            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for i in range(2,n-1):\n",
    "            left=n\n",
    "            temp=\"\"\n",
    "            turn=1\n",
    "            while(left!=0):\n",
    "                cur_num=left%(i**turn)\n",
    "                temp+=str(cur_num)\n",
    "                left-=cur_num\n",
    "                turn+=1\n",
    "            if temp!=temp[::-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:      \n",
    "        def decimal_to_base(num, base):\n",
    "            if num == 0:\n",
    "                return '0'\n",
    "            negative = False\n",
    "            if num < 0:\n",
    "                negative = True\n",
    "                num = abs(num)\n",
    "            result = ''\n",
    "            while num > 0:\n",
    "                remainder = num % base\n",
    "                result = str(remainder) + result\n",
    "                num //= base\n",
    "            if negative:\n",
    "                result = '-' + result\n",
    "            return result\n",
    "        for i in range(2,n-1):\n",
    "            if decimal_to_base(n,i)!=decimal_to_base(n,i)[::-1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for i in range(2,n-1):\n",
    "            left=n\n",
    "            temp=\"\"\n",
    "            turn=1\n",
    "            while(left!=0):\n",
    "                cur_num=left%(i**turn)\n",
    "                temp+=str(cur_num)\n",
    "                left-=cur_num\n",
    "                turn+=1\n",
    "            if temp!=temp[::-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        for i in range(2, n):\n",
    "            x = n\n",
    "            y = \"\"\n",
    "            while x:\n",
    "                y += str(x%i)\n",
    "                x //= i\n",
    "            if y != y[::-1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return not True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def ok(n,b):\n",
    "            res = []\n",
    "            while n:\n",
    "                res.append(n%b)\n",
    "                n//=b\n",
    "            return res == res[::-1]\n",
    "        for b in range(2,n-1):\n",
    "            if not ok(n,b):\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        def zhunafua(a,b):\n",
    "            e=[]\n",
    "            while a!=0:\n",
    "              e.append(a%b)\n",
    "              a=a//b\n",
    "            return e\n",
    "        for b in range(2,n-1):\n",
    "            a=zhunafua(n,b)\n",
    "            h=True\n",
    "            while len(a)>1 and h:\n",
    "                right=a.pop()\n",
    "                left=a.pop(0)\n",
    "                if right==left:\n",
    "                   h=True\n",
    "                else:\n",
    "                   h=False\n",
    "        return h\n",
    "\n",
    "                        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isStrictlyPalindromic(self, n: int) -> bool:\n",
    "        return False"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
